import java.util.concurrent.CountDownLatch;

public class Demo3 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch count = new CountDownLatch(5);
        for (int i = 0; i < 10; i++) {
            int id = i;
            Thread t = new Thread(() -> {
                try {
                    Thread.sleep(1000);
                    System.out.println("线程"+id);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                count.countDown();
            });
            t.start();
        }
        count.await();
        System.out.println("任务完成");
    }
}
